﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DepartmentSystem
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                init();
            }
        }

        public void init()
        {
            string sql = "select * from tb_user where username= '" + Session["username"] + "'";
            DataTable dt = SQLHelper.GetTable(sql);
            if(dt.Rows.Count < 1)
            {
                return;
            }

            TextBox1.Text = dt.Rows[0][0].ToString();
            TextBox2.Text = dt.Rows[0][2].ToString();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string password = TextBox3.Text;

            string password2 = TextBox4.Text;

            if (password != password2)
            {
                Response.Write("<script>alert('请在次确认密码!')</script>");
                TextBox2.Text = "";
                TextBox3.Text = "";
                return;
            }

            string sql2 = "update  tb_user  set password = '" + password + "' where username = '" + Session["username"] + "'";
            if (SQLHelper.executeNoQuery(sql2) != 1)
            {
                Response.Write("<script>alert('更新失败!')</script>");
                return;
            }

            Response.Write("<script>alert('更新成功!')</script>");
            Server.Transfer("DepartmentInfo.aspx");
        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}